<template>
  <el-container class="layout-container">
    <el-header class="header">
      <div class="header-left">
        <AppLogo size="small" color="primary" show-text text="基于大语言模型和提示学习的火电知识图谱构建" />
      </div>
      <div class="header-right">
        <el-dropdown>
          <span class="user-info">
            <el-icon><User /></el-icon>
            {{ userStore.user.username }}
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item disabled>
                <el-tag v-if="userStore.isAdmin" type="danger" size="small">管理员</el-tag>
                <el-tag v-else type="info" size="small">普通用户</el-tag>
              </el-dropdown-item>
              <el-dropdown-item divided @click="handleLogout">
                <el-icon><SwitchButton /></el-icon>
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    
    <el-container>
      <el-aside width="200px" class="sidebar">
        <el-menu
          :default-active="activeMenu"
          router
          @select="handleMenuSelect"
        >

          <el-menu-item index="/extract">
            <el-icon><Document /></el-icon>
            <span>知识抽取</span>
          </el-menu-item>
          
          <el-menu-item index="/graph">
            <el-icon><Connection /></el-icon>
            <span>知识图谱</span>
          </el-menu-item>
          
          <el-menu-item index="/data">
            <el-icon><DataLine /></el-icon>
            <span>数据展示</span>
          </el-menu-item>

          <el-menu-item index="/dictionary">
            <el-icon><Reading /></el-icon>
            <span>领域词典</span>
          </el-menu-item>

          <el-menu-item index="/documents">
            <el-icon><Files /></el-icon>
            <span>文档管理</span>
          </el-menu-item>
          
          <el-menu-item index="/users" v-if="userStore.isAdmin">
            <el-icon><User /></el-icon>
            <span>用户管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <el-main class="main-content">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '../store'
import { ElMessage, ElMessageBox } from 'element-plus'
import { User, SwitchButton, Document, Connection, DataLine, Reading, Files } from '@element-plus/icons-vue'
import AppLogo from '../components/AppLogo.vue'

const router = useRouter()
const route = useRoute()
const userStore = useUserStore()

const activeMenu = computed(() => route.path)

const handleMenuSelect = (index) => {
  console.log('Selected menu:', index)
}

const handleLogout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    userStore.logout()
    ElMessage.success('已退出登录')
    router.push('/login')
  }).catch(() => {})
}
</script>

<style scoped>
/* 使用统一设计系统 */
.layout-container {
  height: 100vh;
  background: var(--bg-secondary);
}

/* Header 样式 - 遵循 Figma 设计风格 */
.header {
  background: var(--bg-primary);
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-2xl);
  height: var(--header-height);
  border-bottom: 1px solid var(--border-lighter);
  position: relative;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-left h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-family);
  letter-spacing: -0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
}

.user-info {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--radius-lg);
  font-family: var(--font-family);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  background: var(--bg-primary);
}


/* Sidebar 样式 */
.sidebar {
  background: var(--bg-primary);
}

:deep(.el-menu) {
  border: none;
  background: var(--bg-primary);
  padding: var(--spacing-md);
}

:deep(.el-menu-item) {
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-normal);
  margin-bottom: var(--spacing-xs);
  border-radius: var(--radius-lg);
  height: 44px;
  line-height: 44px;
  color: var(--text-secondary);
  position: relative;
  overflow: hidden;
  border-left: none !important;
  border-right: none !important;
}

:deep(.el-menu-item.is-active) {
  background: var(--bg-active) !important;
  color: var(--primary-blue) !important;
  font-weight: var(--font-weight-medium);
}

:deep(.el-menu-item.is-active::before) {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--primary-blue);
  border-radius: 0 2px 2px 0;
}

:deep(.el-menu-item .el-icon) {
  font-size: 18px;
  margin-right: var(--spacing-md);
}

/* Main Content 样式 */
.main-content {
  background: var(--bg-secondary);
  padding: 24px;
  overflow-y: auto;
  height: calc(100vh - var(--header-height));
  max-width: 100%;
  width: 100%;
}

/* 滚动条优化 */
.main-content::-webkit-scrollbar {
  width: 6px;
}

.main-content::-webkit-scrollbar-track {
  background: transparent;
}

.main-content::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-full);
}


/* 下拉菜单样式优化 */
:deep(.el-dropdown-menu) {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-lighter);
  padding: var(--spacing-xs);
}

:deep(.el-dropdown-menu__item) {
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-md);
  margin: 2px 0;
}


/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    padding: 0 var(--spacing-lg);
  }
  
  .header-left h2 {
    font-size: var(--font-size-lg);
  }
  
  .sidebar {
    width: 60px !important;
  }
  
  :deep(.el-menu-item span) {
    display: none;
  }
}
</style>

